import bisect
import math

from seaman.core import JsonUtil

from common.method import *
from common.model import InterpolationData
from common.test import get_test_base_data
from service.CompletionService import Completion


# 获取插值井斜角
def get_inclination_v2(a: InterpolationData, b: InterpolationData, D: float, face_angle: float, arc_angle: float):
    # res: float = math.acos(math.cos(b.inclination) * math.cos(arc_angle) -
    # 定义计算元                        math.sin(b.inclination) * math.cos(face_angle) * math.sin(arc_angle))
    cos_arc_angle: float = math.cos(math.radians(arc_angle))
    sin_arc_angle: float = math.sin(math.radians(arc_angle))
    cos_face_angle: float = math.cos(math.radians(face_angle))
    res: float = math.acos(math.cos(math.radians(b.inclination)) * cos_arc_angle -
                           math.sin(math.radians(b.inclination)) * cos_face_angle * sin_arc_angle)
    # print('井斜角:', res)
    return math.degrees(res)


# 返回结果是角度制
# 获取井斜角变化率 插值点工具面角 / 曲率半径 * 30
def get_inclination_rate(data: InterpolationData):
    face_angle: float = data.face_angle
    R: float = data.curvature_radius
    # 度转为弧度
    cos_face_angle: float = math.cos(math.radians(face_angle))
    result: float = cos_face_angle / R
    # return result * 30
    # 弧度转为度
    return math.degrees(result) * 30


# 返回结果是角度制
# 返回方位角变化率 * 30
def get_azimuth_rate(data: InterpolationData):
    face_angle: float = data.face_angle
    R: float = data.curvature_radius
    # 角度转换为弧度
    sin_face_angle: float = math.sin(math.radians(face_angle))
    result: float = sin_face_angle / (R * math.sin(math.radians(data.inclination)))
    # return result * 30
    # 弧度转为角度
    return math.degrees(result) * 30


# 获取插值井斜角
def get_inclination(a: InterpolationData, b: InterpolationData, D: float) -> float:
    # 获取工具面角 Wi
    face_angle = get_face_angle(a, b)
    # 插值点圆弧角
    arc_angle = get_arc_angle(a, b, D)
    # 执行替代方法
    return get_inclination_v2(a, b, D, face_angle, arc_angle)

    # print(degree_to_radian(res))
    # print(res * 180.0 / math.pi)


# # 计算插值点方位角
# def get_azimuth_v2(a: InterpolationData, b: InterpolationData, D: float, face_angle: float, arc_angle: float) -> float:
#     # 定义计算元 a
#     cos_arc_angle: float = math.cos(math.radians(arc_angle))
#     sin_arc_angle: float = math.sin(math.radians(arc_angle))
#     cos_face_angle: float = math.cos(math.radians(face_angle))
#     # factor_a: float = math.cos(b.inclination) * math.sin(arc_angle) + math.sin(b.inclination) * math.cos(
#     # face_angle) * math.cos(arc_angle)
#     factor_a: float = (math.sin(math.radians(b.inclination)) * cos_arc_angle
#                        + math.cos(math.radians(b.inclination)) * cos_face_angle * sin_arc_angle)
#     # print('分子', factor_a)
#     # print(math.cos(math.radians(b.inclination)))
#     # print(math.sin(math.radians(arc_angle)))
#     # 定义计算元 b
#     # factor_b: float = math.pow(math.sin(face_angle), 2) * math.pow(math.sin(arc_angle), 2)
#     factor_b: float = math.pow(math.sin(math.radians(face_angle)), 2) * math.pow(math.sin(math.radians(arc_angle)), 2)
#     # print('factor_b', factor_b)
#     # 定义计算元 c
#     # factor_c: float = math.sin(b.inclination) * math.cos(arc_angle) + math.cos(b.inclination) * math.cos(face_angle) * math.sin(arc_angle)
#     factor_c: float = math.sin(math.radians(b.inclination)) * math.cos(math.radians(arc_angle)) + math.cos(
#         math.radians(b.inclination)) * math.cos(
#         math.radians(face_angle)) * math.sin(math.radians(arc_angle))
#     # print('factor_c', factor_c)
#     # 定义计算元 d
#     factor_d: float = math.sqrt(factor_b + math.pow(factor_c, 2))
#     # print('分母:', factor_d)
#     # 定义计算元 e
#     factor_e: float = math.degrees(math.acos(factor_a / factor_d))
#     # 定义计算结果
#     factor_res: float = b.azimuth - factor_e
#     if factor_res > 0:
#         return factor_res % 360
#     else:
#         return -1 * (math.fabs(factor_res) % 360)


# 计算插值点方位角  ---- 12.12修改
def get_azimuth_v3(a: InterpolationData, b: InterpolationData, D: float, face_angle: float, arc_angle: float) -> float:
    # 定义sin_res 的分子
    factor_a: float = math.sin(math.radians(face_angle)) * math.sin(math.radians(arc_angle))
    # 定义sin_res 分母中的左半部分
    factor_b: float = math.pow(math.sin(math.radians(face_angle)), 2) * math.pow(math.sin(math.radians(arc_angle)), 2)
    # 定义sin_res 分母中的右半部分
    factor_c: float = math.sin(math.radians(b.inclination)) * math.cos(math.radians(arc_angle)) + math.cos(
        math.radians(b.inclination)) * math.cos(
        math.radians(face_angle)) * math.sin(math.radians(arc_angle))
    factor_d: float = math.sqrt(factor_b + math.pow(factor_c, 2))
    sin_res: float = factor_a / factor_d
    # 判断sin_res之后的计算步骤
    cos_arc_angle: float = math.cos(math.radians(arc_angle))
    sin_arc_angle: float = math.sin(math.radians(arc_angle))
    cos_face_angle: float = math.cos(math.radians(face_angle))
    # res 的分子
    factor_e: float = (math.sin(math.radians(b.inclination)) * cos_arc_angle
                       + math.cos(math.radians(b.inclination)) * cos_face_angle * sin_arc_angle)
    factor_f: float = math.degrees(math.acos(factor_e / factor_d))
    # print("当前factor_f:",factor_f)
    res_add: float = b.azimuth + factor_f
    res_sub: float = b.azimuth - factor_f
    if sin_res >= 0:
        if res_add % 360 < 0:
            return res_add % 360 + 360
        else:
            return res_add % 360
    elif sin_res < 0:
        if res_sub % 360 < 0:
            return res_sub % 360 + 360
        else:
            return res_sub % 360
    # if sin_res >= 0:
    #     return res_add % 360
    # elif sin_res < 0:
    #     return res_sub % 360


# 获取插值方位角
def get_azimuth(a: InterpolationData, b: InterpolationData, D: float) -> float:
    # 获取工具面角 Wi
    face_angle = get_face_angle(a, b)
    # 插值点圆弧角 tao
    arc_angle = get_arc_angle(a, b, D)
    return get_azimuth_v3(a, b, D, face_angle, arc_angle)


# 计算 X 坐标
def get_north_v2(a: InterpolationData, b: InterpolationData, D: float, curvature_radius: float, face_angle: float,
                 arc_angle: float) -> float:
    sin_arc_angle: float = math.sin(math.radians(arc_angle))
    cos_arc_angle: float = math.cos(math.radians(arc_angle))
    sin_face_angle: float = math.sin(math.radians(face_angle))
    cos_face_angle: float = math.cos(math.radians(face_angle))
    # print("1-tao:", 1 - cos_arc_angle)
    factor_a: float = math.sin(math.radians(b.inclination)) * math.cos(math.radians(b.azimuth)) * sin_arc_angle
    factor_b: float = math.cos(math.radians(b.inclination)) * math.cos(math.radians(b.azimuth)) * cos_face_angle
    factor_c: float = math.sin(math.radians(b.azimuth)) * sin_face_angle
    # return b.north + curvature_radius * (
    #     math.sin(math.radians(b.inclination)) * math.cos(math.radians(b.azimuth))
    #     * math.sin(math.radians(arc_angle))
    #     -
    #     (
    #
    #     )
    # )
    return b.north + curvature_radius * (factor_a + (factor_b - factor_c) * (1 - cos_arc_angle))


# 获取插值 X 坐标
def get_north(a: InterpolationData, b: InterpolationData, D: float) -> float:
    # 获取曲率半径 Ri,i+1
    curvature_radius = get_curvature_radius(a, b)
    # print('曲率半径为:', curvature_radius)
    # 获取工具面角 Wi
    face_angle = get_face_angle(a, b)
    # print('工具面角为:', face_angle)
    # 插值点圆弧角
    arc_angle = get_arc_angle(a, b, D)
    return get_north_v2(a, b, D, curvature_radius, face_angle, arc_angle)


# 获取插值 Y 坐标
def get_east_v2(a: InterpolationData, b: InterpolationData, D: float, curvature_radius: float, face_angle: float,
                arc_angle: float) -> float:
    sin_arc_angle: float = math.sin(math.radians(arc_angle))
    cos_arc_angle: float = math.cos(math.radians(arc_angle))
    sin_face_angle: float = math.sin(math.radians(face_angle))
    cos_face_angle: float = math.cos(math.radians(face_angle))
    # 定义计算元
    factor_a: float = math.sin(math.radians(b.inclination)) * math.sin(math.radians(b.azimuth)) * sin_arc_angle
    factor_b: float = math.cos(math.radians(b.inclination)) * math.sin(math.radians(b.azimuth)) * cos_face_angle
    factor_c: float = math.cos(math.radians(b.azimuth)) * sin_face_angle
    # 返回 Y 坐标
    # print(b.east)
    return b.east + curvature_radius * (factor_a + (factor_b + factor_c) * (1 - cos_arc_angle))


# 获取插值 Y 坐标
def get_east(a: InterpolationData, b: InterpolationData, D: float) -> float:
    # 获取曲率半径 Ri,i+1
    curvature_radius = get_curvature_radius(a, b)
    # 获取工具面角 Wi
    face_angle = get_face_angle(a, b)
    # 插值点圆弧角
    arc_angle = get_arc_angle(a, b, D)
    return get_east_v2(a, b, D, curvature_radius, face_angle, arc_angle)


# 插值 Z V2
def get_true_vertical_depth_v2(a: InterpolationData, b: InterpolationData, D: float, curvature_radius: float,
                               face_angle: float,
                               arc_angle: float) -> float:
    sin_arc_angle: float = math.sin(math.radians(arc_angle))
    cos_arc_angle: float = math.cos(math.radians(arc_angle))
    sin_face_angle: float = math.sin(math.radians(face_angle))
    cos_face_angle: float = math.cos(math.radians(face_angle))
    # 计算元
    factor_a: float = math.cos(math.radians(b.inclination)) * sin_arc_angle
    factor_b: float = math.sin(math.radians(b.azimuth)) * cos_face_angle
    # 返回 Z 坐标
    return b.true_vertical_depth + curvature_radius * (factor_a - factor_b * (1 - cos_arc_angle))


# 获取插值 Z 坐标
def get_true_vertical_depth(a: InterpolationData, b: InterpolationData, D: float) -> float:
    # 获取曲率半径 Ri,i+1
    curvature_radius = get_curvature_radius(a, b)
    # 获取工具面角 Wi
    face_angle = get_face_angle(a, b)
    # 插值点圆弧角
    arc_angle = get_arc_angle(a, b, D)
    return get_true_vertical_depth_v2(a, b, D, curvature_radius, face_angle, arc_angle)


# 获取曲率半径 依赖于全角计算
def get_curvature_radius(a: InterpolationData, b: InterpolationData) -> float:
    # print(JsonUtil.obj2str(a))
    # print(JsonUtil.obj2str(b))
    # print(get_full_angle(a,b))
    try:
        # 需要将全角转化为弧度
        return get_delta_depth(a, b) * math.pow(math.radians(get_full_angle(a, b)), -1)
    except Exception:
        print("#### 全角计算结果 #########")
        print(JsonUtil.obj2str(a))
        print(JsonUtil.obj2str(b))
        print(get_full_angle(a, b))



# 计算全角
def get_full_angle(a: InterpolationData, b: InterpolationData) -> float:
    # return math.acos(math.cos(b.inclination) * math.cos(a.inclination) +
    #                  math.sin(b.inclination) * math.sin(a.inclination)
    #                  * math.cos(get_delta_azimuth(a, b)))
    factor_res: float = math.acos(math.cos(math.radians(b.inclination)) * math.cos(math.radians(a.inclination)) +
                                  math.sin(math.radians(b.inclination)) * math.sin(math.radians(a.inclination))
                                  * math.cos(math.radians(get_delta_azimuth(a, b))))
    # print("######## interpolation.py 225 ############")
    # print(factor_res)
    return math.degrees(factor_res)


# 计算圆弧角
# D为所求插值点井深，人为给定，且D > D_i
def get_arc_angle(a: InterpolationData, b: InterpolationData, D: float) -> float:
    if D <= b.depth or D >= a.depth:
        print("D不满足条件")
    res: float = (D - b.depth) / get_curvature_radius(a, b)
    # 转化为角度
    return math.degrees(res)


# 计算圆弧角
# D为所求插值点井深，人为给定，且D > D_i
# R是曲率半径
def get_arc_angle_v2(a: InterpolationData, b: InterpolationData, D: float, R: float) -> float:
    if D <= b.depth or D >= a.depth:
        print("D不满足条件")
    res: float = (D - b.depth) / R
    # 转化为角度
    return math.degrees(res)


# # 获取插值工具面角 v2
# def get_inter_face_angle_v2(a: InterpolationData, b: InterpolationData, D: float, arc_angle: float,
#                             face_angle: float) -> float:
#     # 定义分子计算元
#     factor_a: float = math.cos(math.radians(b.inclination)) * math.sin(math.radians(arc_angle))
#     factor_b: float = math.sin(math.radians(b.inclination)) * math.cos(math.radians(face_angle)) * math.cos(
#         math.radians(arc_angle))
#     # 定义分母计算元
#     factor_c: float = math.pow(math.sin(math.radians(face_angle)), 2) * math.pow(math.sin(math.radians(arc_angle)), 2)
#     factor_d: float = math.sin(math.radians(b.inclination)) * math.cos(math.radians(arc_angle)) + math.cos(
#         math.radians(b.inclination)) * math.cos(math.radians(face_angle)) * math.sin(math.radians(arc_angle))
#     factor_e: float = math.pow(factor_d, 2)
#     # 2023-11-15 @zy 提出 正负号保留问题，遵循公式计算原则
#     factor_f: float = (factor_a + factor_b) / math.sqrt(factor_c + factor_e)
#     # factor_f: float = math.sqrt(math.pow((factor_a + factor_b), 2) / (factor_c + factor_e))
#     # print(factor_f)
#     # 定义结果
#     if factor_f > 1:
#         print(factor_f)
#         factor_f = 0.999999999999999999
#     elif factor_f < -1:
#         print(factor_f)
#         factor_f = -0.9999999999999999
#     factor_res: float = 360 - math.degrees(math.acos(factor_f))
#     return factor_res

# 获取插值工具面角 v3 -----12.12修改
def get_inter_face_angle_v3(a: InterpolationData, b: InterpolationData, D: float, arc_angle: float, face_angle: float, full_angle: float) -> float:
    # factor_a: float = math.sin(math.radians(a.inclination)) * math.sin(math.radians(get_delta_azimuth(a, b)))
    # # 计算初始工具面角的sin值
    # sin_face_angle: float = factor_a / math.sin(math.radians(full_angle))
    # 定义sin_res 的分子
    factor_a: float = math.sin(math.radians(face_angle)) * math.sin(math.radians(arc_angle))
    # 定义sin_res 分母中的左半部分
    factor_b: float = math.pow(math.sin(math.radians(face_angle)), 2) * math.pow(math.sin(math.radians(arc_angle)), 2)
    # 定义sin_res 分母中的右半部分
    factor_c: float = math.sin(math.radians(b.inclination)) * math.cos(math.radians(arc_angle)) + math.cos(
        math.radians(b.inclination)) * math.cos(
        math.radians(face_angle)) * math.sin(math.radians(arc_angle))
    factor_d: float = math.sqrt(factor_b + math.pow(factor_c, 2))
    sin_res: float = factor_a / factor_d
    # 定义分子计算元
    factor_a: float = math.cos(math.radians(b.inclination)) * math.sin(math.radians(arc_angle))
    factor_b: float = math.sin(math.radians(b.inclination)) * math.cos(math.radians(face_angle)) * math.cos(
        math.radians(arc_angle))
    # 定义分母计算元
    factor_c: float = math.pow(math.sin(math.radians(face_angle)), 2) * math.pow(math.sin(math.radians(arc_angle)), 2)
    factor_d: float = math.sin(math.radians(b.inclination)) * math.cos(math.radians(arc_angle)) + math.cos(
        math.radians(b.inclination)) * math.cos(math.radians(face_angle)) * math.sin(math.radians(arc_angle))
    factor_e: float = math.pow(factor_d, 2)
    # 2023-11-15 @zy 提出 正负号保留问题，遵循公式计算原则
    factor_f: float = (factor_a + factor_b) / math.sqrt(factor_c + factor_e)
    # factor_f: float = math.sqrt(math.pow((factor_a + factor_b), 2) / (factor_c + factor_e))
    # print(factor_f)
    # 定义结果
    if sin_res >= 0:
        # print('$$$$$$$', D)
        # print(factor_f)
        if factor_f > 1.0:
            factor_f = 0.99999999999999999999
        elif factor_f < -1.0:
            factor_f = -0.99999999999999999
        factor_res = math.degrees(math.acos(factor_f))
        return factor_res
    elif sin_res < 0:
        # print('$$$$$$$', D)
        # print(factor_f)
        if factor_f > 1.0:
            factor_f = 0.99999999999999999999
        elif factor_f < -1.0:
            factor_f = -0.99999999999999999
        factor_res: float = 360 - math.degrees(math.acos(factor_f))
        return factor_res


# 获取插值工具面角
def get_inter_face_angle(a: InterpolationData, b: InterpolationData, D: float) -> float:
    # 获取圆弧角
    arc_angle = get_arc_angle(a, b, D)
    # 获取工具面角
    face_angle = get_face_angle(a, b)
    # 获取全角
    full_angle = get_full_angle(a, b)
    # 求解值
    return get_inter_face_angle_v3(a, b, D, arc_angle, face_angle, full_angle)


# 计算初始工具面角度 V2
def get_face_angle_v2(a: InterpolationData, b: InterpolationData, full_angle: float) -> float:
    # print('全角为:', get_full_angle(a, b))
    # print(degree_to_radian(get_full_angle(a, b)))
    sin_full_angle: float = math.sin(math.radians(full_angle))
    # print('分母', sin_full_angle)
    # 定义计算元 a
    factor_a: float = math.sin(math.radians(a.inclination)) * math.sin(math.radians(get_delta_azimuth(a, b)))
    # 计算初始工具面角的sin值
    sin_face_angle: float = factor_a / math.sin(math.radians(full_angle))
    # sin_face_angle: float = ()
    # print('sin工具面角', sin_face_angle)

    # 计算初始工具面角用到的分子
    # numerator: float = (math.cos(b.inclination) * math.sin(a.inclination)
    #                     * math.cos(get_delta_azimuth(a, b)) -
    #                     math.sin(b.inclination) * math.cos(a.inclination))
    numerator: float = (math.cos(math.radians(b.inclination)) * math.sin(math.radians(a.inclination))
                        * math.cos(math.radians(get_delta_azimuth(a, b))) -
                        math.sin(math.radians(b.inclination)) * math.cos(math.radians(a.inclination)))
    # 定义计算元
    factor_f: float = numerator / math.sin(math.radians(full_angle))
    if factor_f < -1:
        factor_f = -1
    elif factor_f > 1:
        factor_f = 1
    factor_res = math.acos(factor_f)
    # print('factor_res,', factor_res)
    # numerator: float = (math.cos(math.radians(b.inclination)) * math.sin(math.radians(b.inclination))
    #                     * math.cos(math.radians(get_delta_azimuth(a, b))) -
    #                     math.sin(math.radians(b.inclination)) * math.cos(math.radians(a.inclination)))
    if sin_face_angle < 0:
        return 360 - math.degrees(factor_res)
    else:
        return math.degrees(factor_res)


# 计算初始工具面角
def get_face_angle(a: InterpolationData, b: InterpolationData) -> float:
    # 获取全角的值
    full_angle = get_full_angle(a, b)
    return get_face_angle_v2(a, b, full_angle)

# 比较是否相等，判断是否为直井
def compare_sim(a: InterpolationData, b: InterpolationData) -> bool:
    if a.inclination == b.inclination and a.azimuth == b.azimuth:
        return True
    return False

# 数值补全
class Interpolation:
    _list_: List[InterpolationData]
    _space_: float

    def __init__(self, _list_: [CompletionData], _space_: float = 1.0):
        list_size: int = len(_list_)
        t_list: List[InterpolationData] = []
        for idx in range(0, list_size):
            t: InterpolationData = InterpolationData(_list_[idx])
            if idx == 0:
                t.dog_leg_severity = 0
                t.face_angle = 0.0
                t.arc_angle = 0.0
                t.face_angle = 0.0
                t.full_angle = 0.0
                t.curvature_radius = 0.0
                t.inclination_rate = 0.0
                t.azimuth_rate = 0.0
            t_list.append(t)
        self._list_ = t_list
        self._space_ = _space_

    # 计算圆弧角
    # D为所求插值点井深，人为给定，且D > D_i
    # R是曲率半径
    def get_arc_angle(a: InterpolationData, b: InterpolationData, D: float, R: float) -> float:
        if D <= b.depth or D >= a.depth:
            print("D不满足条件")
        res: float = (D - b.depth) / R
        # 转化为角度
        return math.degrees(res)

    # 数据筛选
    def filter(self, _space_: float, is_slanting_point: bool):
        # 执行过滤操作
        filter_list: List[InterpolationData] = [self._list_[0]]
        # 最大深度
        filter_list_depth_max = self._list_[0].depth
        print("当前没有造斜点的第一个点是：",filter_list_depth_max)
        filter_list.append(self._list_[1])


        if len(self._list_) >= 1000:
            if is_slanting_point:
                filter_list_depth_max = self._list_[1].depth
                print("当前存在造斜点的第一个点是：", filter_list_depth_max)
            for item in self._list_:
                if item.depth >= filter_list_depth_max + 50:
                    print(JsonUtil.obj2str(item))
                    filter_list.append(item)
                    filter_list_depth_max = item.depth
            filter_list.append(self._list_[-1])

        else:
            for item in self._list_:
                if item.depth >= filter_list_depth_max + _space_:
                    print(JsonUtil.obj2str(item))
                    filter_list.append(item)
                    filter_list_depth_max = item.depth
            filter_list.append(self._list_[-1])

                # if item.inclination == 0.0 and item.azimuth == 0.0:
                #     continue
                # 直井 --> 保留
                # elif item.inclination == filter_list[-1].inclination and item.azimuth == filter_list[-1].azimuth:
                #     continue
                # else:
                #     # print(JsonUtil.obj2str(item))
                #     filter_list.append(item)
                #     filter_list_depth_max = item.depth
        self._list_ = filter_list
        return filter_list

    def execute(self):
        _list_: [InterpolationData] = self._list_
        depth_list: List[float] = [item.depth for item in _list_]
        # 获取最大井深
        dept_max: int = int(_list_[-1].depth)
        # 获取开始点位置
        dept_min: int = int(_list_[0].depth)
        # 构建插值数据列表
        inter_data_list: List[InterpolationData] = []
        # 设置插值点
        inter_depth: float = _list_[0].depth
        # 补全第一元素
        while inter_depth <= dept_max:
            # 返回大于等于 inter_depth 的第一个下标
            idx = bisect.bisect_left(depth_list, inter_depth)
            # 如果是已存在元素
            if inter_depth == depth_list[idx]:
                # 深度为 0 补丁3
                if inter_depth == _list_[0].depth:
                    # 第一个点加入
                    data: InterpolationData = _list_[idx]
                    inter_data_list.append(data)
                else:
                    # 取上一个元素插值点计算结果， 这就需要处理，保证两个数据之间的距离，必须大于插值距离 space
                    # 如果 两点深度距离<= space ，那么很显然，可能会导致连续的 0 出现
                    data: InterpolationData = _list_[idx]
                    data.dog_leg_severity = inter_data_list[-1].dog_leg_severity
                    data.curvature_radius = inter_data_list[-1].curvature_radius
                    data.full_angle = inter_data_list[-1].full_angle
                    data.arc_angle = inter_data_list[-1].arc_angle
                    data.face_angle = inter_data_list[-1].face_angle
                    data.inclination_rate = inter_data_list[-1].inclination_rate
                    data.azimuth_rate = inter_data_list[-1].azimuth_rate
                    inter_data_list.append(data)
            else:
                # 前后插值
                # delta_depth: float = get_delta_depth(_list_[idx], _list_[idx-1])
                # print('#######', inter_depth)
                inter_data: InterpolationData = InterpolationData(_list_[idx])
                # 设置深度
                inter_data.depth = inter_depth
                # 相似度比较
                if compare_sim(_list_[idx], _list_[idx-1]):
                    # print("_list_[idx-1].north",_list_[idx-1].north)
                    # print("inter_depth",inter_depth)
                    # print("_list_[idx - 1].depth",_list_[idx - 1].depth)
                    # print("_list_[idx].depth",_list_[idx].depth)
                    # print("_list_[idx-1].inclination",_list_[idx-1].inclination)
                    # print("_list_[idx-1].azimuth",_list_[idx-1].azimuth)

                    inter_data.curvature_radius = 0.0
                    inter_data.face_angle = 0.0
                    inter_data.arc_angle = 0.0
                    inter_data.inclination_rate = 0
                    inter_data.azimuth_rate = 0
                    inter_data.dog_leg_severity = 0.0
                    # 3 个计算公式 补全
                    # x
                    inter_data.north = _list_[idx-1].north + (inter_depth - _list_[idx - 1].depth) * math.sin(math.radians(_list_[idx-1].inclination) * math.cos(math.radians(_list_[idx-1].azimuth)))
                    # y
                    inter_data.east = _list_[idx-1].east + (inter_depth - _list_[idx - 1].depth) * math.sin(math.radians(_list_[idx-1].inclination) * math.sin(math.radians(_list_[idx-1].azimuth)))
                    # z
                    inter_data.true_vertical_depth = _list_[idx-1].true_vertical_depth + (inter_depth - _list_[idx - 1].depth) * math.cos(math.radians(_list_[idx-1].inclination))
                    # 插入
                    inter_data_list.append(inter_data)
                    # 插值深度迭加
                    inter_depth = inter_depth + self._space_
                    # 执行
                    continue


                # ---> 旧写法

                # 计算曲率半径
                curvature_radius: float = get_curvature_radius(_list_[idx], _list_[idx - 1])
                inter_data.curvature_radius = curvature_radius
                # 计算全角
                full_angle: float = get_full_angle(_list_[idx], _list_[idx - 1])
                inter_data.full_angle = full_angle
                # 计算圆弧角
                arc_angle: float = Interpolation.get_arc_angle(_list_[idx], _list_[idx - 1], inter_depth,
                                                               curvature_radius)
                inter_data.arc_angle = arc_angle
                # 狗腿度
                dog_leg_severity: float = full_angle * 30 / get_delta_depth(_list_[idx], _list_[idx - 1])
                inter_data.dog_leg_severity = dog_leg_severity
                # 计算工具面角
                face_angle: float = get_face_angle(_list_[idx], _list_[idx - 1])
                # 插值点工具面角度
                # inter_face_angle = get_inter_face_angle_v2(_list_[idx], _list_[idx - 1], inter_depth, arc_angle,
                #                                            face_angle)
                inter_face_angle = get_inter_face_angle_v3(_list_[idx], _list_[idx - 1], inter_depth, arc_angle,
                                                           face_angle, full_angle)
                inter_data.face_angle = inter_face_angle
                # 插值点井斜角
                inclination: float = get_inclination_v2(_list_[idx], _list_[idx - 1], inter_depth, face_angle,
                                                        arc_angle)
                inter_data.inclination = inclination
                # 插值点方位角
                # azimuth: float = get_azimuth_v2(_list_[idx], _list_[idx - 1], inter_depth, face_angle, arc_angle)
                azimuth: float = get_azimuth_v3(_list_[idx], _list_[idx - 1], inter_depth, face_angle, arc_angle)
                inter_data.azimuth = azimuth
                # 获取X坐标
                north: float = get_north_v2(_list_[idx], _list_[idx - 1], inter_depth, curvature_radius, face_angle,
                                            arc_angle)
                inter_data.north = north

                # 获取 y 坐标
                east: float = get_east_v2(_list_[idx], _list_[idx - 1], inter_depth, curvature_radius, face_angle,
                                          arc_angle)
                inter_data.east = east

                # # 获取 z 坐标
                true_vertical_depth: float = get_true_vertical_depth_v2(_list_[idx], _list_[idx - 1], inter_depth,
                                                                        curvature_radius, face_angle,
                                                                        arc_angle)
                inter_data.true_vertical_depth = true_vertical_depth
                # 获取插值井斜角变化率
                inter_data.inclination_rate = get_inclination_rate(inter_data)
                # 获取插值方位角变化率
                inter_data.azimuth_rate = get_azimuth_rate(inter_data)
                # print(JsonUtil.obj2str(inter_data))
                # 插入
                inter_data_list.append(inter_data)
            # 插值深度迭加
            inter_depth = inter_depth + self._space_
        # 遍历
        return inter_data_list


# if __name__ == '__main__':
#     data_list: List[BaseData] = get_test_base_data()
#     completion = Completion(data_list)
#     _list_: List[CompletionData] = completion.execute()
#     interpolation = Interpolation(_list_, 1.0)
#     inter_list: List[InterpolationData] = interpolation.execute()
#     for item in inter_list:
#         print(JsonUtil.obj2str(item))
